package com.nowoe.mvc.parse;

import com.nowoe.mvc.exception.ParseException;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.InputStream;

/**
 * @author 倚栏听风 2023/9/15 14:23
 */
public class XMLParser {
    public static String getCtxClassName(String path, String name) {
        SAXReader saxReader = new SAXReader();
        InputStream inputStream = XMLParser.class.getClassLoader().getResourceAsStream(path);
        Document document = null;
        try {
            document = saxReader.read(inputStream);
        } catch (DocumentException e) {
            throw new ParseException(path + "解析失败 ：" + e.getMessage());
        }
        Element rootElement = document.getRootElement();
        Element element = rootElement.element(name);
        if (element == null) {
            return "";
        }
        return element.attributeValue("value");
    }
}
